<!doctype html>
<html>
	<head>
		<title>消息发送管理</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf8" />
		<link href='css/bootstrap.min.css' rel="stylesheet" />
		<link href="css/style.css" type="text/css" rel="stylesheet"/>
    	<script type="text/javascript" src="js/jquery.min.js"></script>
		<script src="js/lang.js" type="text/javascript" charset="utf8"></script>
		<script src="js/common.js" type="text/javascript" charset="utf8"></script>
	</head>
	<body>
		
		<div class="container-fluid">
      		<div class="row-fluid">
        		<div class="span12">
          				<h3>Sequence Stat</h3>
          				<h5><a href="javascript:void(0);" class="lang" langKey="Add">Add</a></h5>
						<table id="dataTable" class="table table-bordered table-striped responsive-utilities">
							<thead>
								<tr>
									<th><a href="javascript:void(0);" class="lang" langKey="No">No</a></th>
									<th><a id="th-SequenceName" href="javascript:void(0);" class="lang" langKey="SequenceName">sequenceName</a></th>
									<th><a id="th-CurrentValue" href="javascript:void(0);" class="lang" langKey="CurrentValue">CurrentValue</a></th>
									<th><a id="th-Increment" href="javascript:void(0);" class="lang" langKey="Increment">Increment</a></th>
									<th><a id="th-Total" href="javascript:void(0);" class="lang" langKey="Total">Total</a></th>
									<th><a id="th-Threshold" href="javascript:void(0);" class="lang" langKey="Threshold">Threshold</a></th>
									<th><a href="javascript:void(0);" class="lang" langKey="Operator">Operator</a></th>
								</tr>
							</thead> 
							<tbody></tbody>
						</table>
          			</div>
        		</div>
    	</div>
    	<script type="text/javascript">
	    	$.namespace("common.sequence");
	    	common.sequence = function () {  
	    		return  {
	    			init : function() {
	    				common.common.buildHead(1);
	    				$("#dataTable th a").click(function(obj) {
	    					if(obj.target.id != null){
	    						common.common.setOrderBy(obj.target.id.substring(3));
	    					}
	    				});
	    				common.common.ajaxuri = 'sequence/loadAll.json?';
	    				common.common.handleAjaxResult = common.sequence.handleAjaxResult;
	    				common.common.ajaxRequestForBasicInfo();
	    				setInterval("common.common.ajaxRequestForBasicInfo();",5000);
	    			},
	    			
	    			handleAjaxResult : function(result) {
	    				console.info(result);
	    				if(result.success==false){
	    					var msg = common.common.buildError(result.message);
	    					$("#dataTable tbody").html("<tr><td colspan='6'>"+msg+"</td></tr>");
	    					return;
	    				}
	    				var dataList = result.data.list;
	    				if(result.success == true && dataList.size == 0){
	    					var msg = common.common.buildNotRecordFound();
	    					$("#dataTable tbody").html("<tr><td colspan='6'>"+msg+"</td></tr>");
	    					return;
	    				}
	    				
	    				var seqStatTable = document.getElementById("dataTable");
	    				while (seqStatTable.rows.length > 1) {
	    					seqStatTable.deleteRow(1);
	    				}
	    				
	    				var html = "";
	    				for ( var i = 0; i < dataList.length; i++) {
	    					var data = dataList[i];
	    					var newRow = seqStatTable.insertRow(-1);
	    					html += "<tr>";
	    					html += "<td>" + (i + 1) + "</td>";
	    					html += "<td>" + data.name + "</td>";
	    					html += "<td>" + data.currentValue + "</td>";
	    					html += "<td>" + data.increment + "</td>";
	    					html += "<td>" + data.total + "</td>";
	    					html += "<td>" + data.threshold + "</td>";
	    					html += "<td><a href='javascript:void(0);' onclick=removeSeq('"+data.name+"') class='lang' langKey='Delete'>Delete</td>";
	    					html += "</tr>";
	    				}
	    				$("#dataTable tbody").html(html);
	    				common.common.stripes();
	    			}
	    		}
	    	}();
	
	    	$(document).ready(function() {
	    		common.sequence.init();
	    	});
	    	function removeSeq(name){
	    		if(!confirm("Are you sure to remove this?")){
					return;
				}
	    		common.common.ajaxuri = 'sequence/remove.json?seqName='+name;
				common.common.handleAjaxResult = function(result){
					if(result.success == true){
						window.location.reload();
					}
				};
	    	}
		</script>
	</body>
</html>
